All files / src/app/api/admin/dev-tools/docs/plans/[slug] route.ts

0% Statements 0/33
100% Branches 0/0
0% Functions 0/1
0% Lines 0/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                                                   
/**
 * Single Plan API
 * GET /api/admin/dev-tools/docs/plans/[slug] - Get plan by slug
 */

import { NextRequest, NextResponse } from 'next/server';
import { } from 'next-auth';
import {
  withAdmin,
  withErrorHandling,
  successResponse,
  ApiError,
  ApiSuccessResponse,
  ApiErrorResponse } from '@/lib/api';
import { RouteContext } from '@/lib/api/middleware';
import { getPlanBySlug } from '@/lib/dev-tools/markdown-parser';

/**
 * GET - Get plan by slug
 */
async function handleGet(request: NextRequest,
  context: RouteContext | undefined): Promise<NextResponse<ApiSuccessResponse<unknown> | ApiErrorResponse>> {
  const { slug } = await (context as { params: Promise<{ slug: string }> }).params;
  const plan = await getPlanBySlug(slug);

  if (!plan) {
    throw ApiError.notFound('Plan');
  }

  return successResponse({ plan });
}

export const GET = withErrorHandling(withAdmin(handleGet));